import type { Module, ActionContext } from 'vuex'
import type { AxiosResponse } from 'axios'
import type { runmapStateType } from './typings'
import {
  hardwareTreeGet,
  hardwarePointPositionGet,
  hardwareGetRunDataGet,
  hardwareGetRunAlarmDataDataGet,
  excuteCommandParamPost,
  hardwareGetCommandParam
} from '~/api/monitor/runmap'

const event: Module<runmapStateType, runmapStateType> = {
  namespaced: true,
  state: {
    runStatus: 1
  },
  getters: {
    runStatus: (state) => state.runStatus
  },
  mutations: {
    SET_RUNSTATUS(state, payload) {
      state.runStatus = payload
    }
  },
  actions: {
    //  状态修改
    async GetrunStatus<S, T>({ commit }: ActionContext<S, T>, value: number) {
      commit('SET_RUNSTATUS', value)
    },
    //  查询树
    async HardwareTreeGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await hardwareTreeGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    //  查询监控箱点位分布
    async HardwarePointPositionGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await hardwarePointPositionGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    //  查询监控箱运行数据
    async HardwareGetRunDataGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await hardwareGetRunDataGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    //  查询监控箱警报
    async HardwareGetRunAlarmDataDataGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await hardwareGetRunAlarmDataDataGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    //  执行设备指令
    async ExcuteCommandParamPost<S, T>(_: ActionContext<S, T>, params: T) {
      return await excuteCommandParamPost<T>(params).then((res: AxiosResponse) => res?.data)
    },
    //  获取操作及命令
    async HardwareGetCommandParam<S, T>(_: ActionContext<S, T>, params: T) {
      return await hardwareGetCommandParam<T>(params).then((res: AxiosResponse) => res?.data)
    }
  }
}

export default event
